/**
 * 
 */
package com.ms.game.slot.base;

import com.ms.game.common.container.BasicSettingUtil;
import com.ms.game.common.container.GameTypeInfo;
import com.ms.game.slot.base.message.SGmtoolCleanDoormanSeatStatusRequest;
import com.ms.service.error.ErrorCode;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.group.transportlayer.GroupMessage;
import com.xpec.c4.service.message.MessageAction;

/**
 * @author TW15010
 *
 */
public class SlotGameGmToolAPI {
	/**
	 * 
	 * @param gameType
	 *            遊戲名稱 SGJS, MGDH ....
	 * @param hallType
	 * @param seatId
	 * @param keepDataPlayerId
	 *            player keep data 裡面的 player id, 沒有就填 null
	 * @param offlineKeep
	 *            player keep data 裡面的是否離線保留, keepDataPlayerId = null 就會忽略這個參數
	 * @return
	 */
	public static int clearGameSeat(String gameType, String hallType, String seatId, String keepDataPlayerId,
			boolean offlineKeep) {
		if (!GameUtility.isHaveString(gameType)) {
			return ErrorCode.INVALID_GAME_NAME;
		}

		// 取得指定的遊戲 doorman module id
		GameTypeInfo info = BasicSettingUtil.getGameTypeInfo(gameType);
		if (info == null) {
			return ErrorCode.INVALID_GAME_NAME;
		}

		String doormanModuleId = info.getModuleId();

		// 送出清除座位要求給 doorman
		SGmtoolCleanDoormanSeatStatusRequest request = new SGmtoolCleanDoormanSeatStatusRequest();
		request.setGamename(gameType);
		request.setHalltype(hallType);
		request.setSeatid(seatId);
		request.setKeepDataPlayerId(keepDataPlayerId);
		request.setOfflineKeep(offlineKeep);
		request.setFromDataCenterLite(false);

		GroupMessage msg = new GroupMessage();
		msg.setMessageType(MessageTypes.S_GMTOOL_CLEAN_DOORMAN_SEAT_STATUS);
		msg.setMessageContent(request);
		msg.setDestModuleID(doormanModuleId);

		// 等待 doorman 回覆
		int errorCode = (int) MessageAction.sendMessageWaitResponse(msg);

		return errorCode;
	}
}
